Skip to content

feat: add pool_exists(asset) -> bool public view entrypoint - #246

Merged
Jagadeeshftw merged 1 commit into
AnchorNet-Org:mainfrom
retkatmun:feat/pool-exists-view
Jul 27, 2026
Merged

feat: add pool_exists(asset) -> bool public view entrypoint#246
Jagadeeshftw merged 1 commit into
AnchorNet-Org:mainfrom
retkatmun:feat/pool-exists-view

Conversation

@retkatmun

Copy link
Copy Markdown
Contributor

Summary

Closes #106

Exposes a pool_exists(env, asset) -> bool entrypoint on AnchornetContract so off-chain integrators can check whether any liquidity has ever been provided for an asset without having to catch Error::PoolNotFound from pool().

Changes

src/lib.rs

  • Added pool_exists(env, asset) -> bool immediately after pool() in the pool-view section. Delegates directly to the already-existing storage::has_pool — no new storage helper needed.
  • Fixed a pre-existing compile error: the list_settlements_by_anchor_and_asset client alias referenced the non-existent method list_settlements_by_anchor_asset instead of the actual exported symbol list_settlements_by_anch_asset.

src/test.rs

Added 6 test cases covering all acceptance criteria:

Test What it verifies
test_pool_exists_false_before_any_liquidity Returns false for an asset that has never had liquidity provided
test_pool_exists_true_after_provide_liquidity Returns true after provide_liquidity
test_pool_exists_true_after_provide_liquidity_multi Returns true after provide_liquidity_multi
test_pool_exists_true_after_full_withdrawal Stays true even after the pool is drained to zero (pool entry persists, matching list_assets behaviour)
test_pool_exists_is_per_asset Independence per asset — funding one asset does not affect another
test_pool_exists_consistent_with_pool_getter pool_exists == false ↔ pool() == PoolNotFound, pool_exists == true ↔ pool() succeeds

README.md

  • Added pool_exists(asset) row to the contract interface table between pool and total_liquidity.

Acceptance criteria

  • pool_exists(asset) returns false for an asset that has never had liquidity provided
  • pool_exists(asset) returns true once provide_liquidity / provide_liquidity_multi has touched that asset
  • pool() behavior and Error::PoolNotFound are unchanged

Security

Pure read view — no state mutation, no authorization requirement. Off-chain integrators can check pool existence without speculative calls that would otherwise revert.

Closes AnchorNet-Org#106

- Add pool_exists(env, asset) -> bool to AnchornetContract in src/lib.rs,
  delegating directly to storage::has_pool which already existed internally.
  Placed immediately after pool() in the pool-view section.

- Fix pre-existing compile error: client alias list_settlements_by_anchor_and_asset
  referenced a non-existent method name list_settlements_by_anchor_asset;
  corrected to list_settlements_by_anch_asset (the actual exported symbol).

- Add 6 regression tests in src/test.rs:
    test_pool_exists_false_before_any_liquidity
    test_pool_exists_true_after_provide_liquidity
    test_pool_exists_true_after_provide_liquidity_multi
    test_pool_exists_true_after_full_withdrawal
    test_pool_exists_is_per_asset
    test_pool_exists_consistent_with_pool_getter

- Update README.md contract interface table with the new read-only entrypoint.

pool() error-returning behavior and Error::PoolNotFound are unchanged.
No authorization required (pure read view, no state mutation).
@Jagadeeshftw
Jagadeeshftw merged commit 1a52db5 into AnchorNet-Org:main Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add pool_exists(asset) as a boolean check that avoids the PoolNotFound error path

2 participants